package masterjava.admingui.shared.entity;

import masterjava.admingui.shared.RoleType;
import masterjava.common.shared.util.SerializeUtil;
import org.jetbrains.annotations.Nullable;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * User: Grigory Kislin
 * Date: 23/06/11
 */
@Entity
@Table(name = "PARTNER")
@Access(AccessType.PROPERTY)
public class Partner extends Client {

    public Partner() {
    }

    public Partner(RoleType role, String email, String name) {
        super(role, email);
        this.name = name;
    }

    public Partner(RoleType role, String email, String address, Date startDate, Date endDate, String comments, Attachment logo, String name, String webSite) {
        super(role, email, address, startDate, endDate, comments, logo);
        this.name = name;
        this.webSite = webSite;
    }

    private String name;

    private String webSite;

    private List<UserLogin> users;

    @Column(name = "NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "WEB_SITE")
    public String getWebSite() {
        return webSite;
    }

    public void setWebSite(String webSite) {
        this.webSite = webSite;
    }

    // Fetch partner with users
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "partner")
    public List<UserLogin> getUsers() {
        return users;
    }

    public void setUsers(@Nullable List<UserLogin> users) {
        this.users = users;
    }

    @Override
    public void prepareToSerialize() {
        super.prepareToSerialize();
        users = SerializeUtil.getSerializedCollection(users);
    }
}
